﻿// ....................................................................................................................
//	Author: Copyright (C) 2012 Ing. Marek Hubal
//	Email: hubal@acasoftware.org
// ....................................................................................................................

using System;
using System.Runtime.InteropServices;

namespace core
{
    /// <summary>Trieda IWin32</summary>
	public class IWin32
    {
        #region delegates
        public delegate int BFFCALLBACK(IntPtr hwnd, uint uMsg, IntPtr lParam, IntPtr lpData);
        #endregion
        #region konstanty
            public const int INVALID_HANDLE_VALUE = -1;
            public const uint FILE_ATTRIBUTE_READONLY = 0x00000001;
            public const uint FILE_ATTRIBUTE_HIDDEN = 0x00000002;
            public const uint FILE_ATTRIBUTE_SYSTEM = 0x00000004;
            public const uint FILE_ATTRIBUTE_DIRECTORY = 0x00000010;
            public const uint FILE_ATTRIBUTE_ARCHIVE = 0x00000020;
            public const uint FILE_ATTRIBUTE_DEVICE = 0x00000040;
            public const uint FILE_ATTRIBUTE_NORMAL = 0x00000080;
            public const uint FILE_ATTRIBUTE_TEMPORARY = 0x00000100;
            public const uint FILE_ATTRIBUTE_SPARSE_FILE = 0x00000200;
            public const uint FILE_ATTRIBUTE_REPARSE_POINT = 0x00000400;
            public const uint FILE_ATTRIBUTE_COMPRESSED = 0x00000800;
            public const uint FILE_ATTRIBUTE_OFFLINE = 0x00001000;
            public const uint FILE_ATTRIBUTE_NOT_CONTENT_INDEXED = 0x00002000;
            public const uint FILE_ATTRIBUTE_ENCRYPTED = 0x00004000;
            public const uint FILE_ATTRIBUTE_VIRTUAL = 0x00010000;
            public const uint INVALID_FILE_ATTRIBUTES = 0xffffffff;
            public const uint BIF_NONEWFOLDERBUTTON = 0x0200;
            public const uint BFFM_INITIALIZED = 1;
            public const uint BFFM_SETSELECTIONA = (IWin32.WM_USER + 102);
            public const uint WM_USER = 0x0400;
            public const int IOCTL_STORAGE_GET_MEDIA_TYPES_EX = (0x0000002d << 16) | (0x0301 << 2);
            public const uint AccessReadWrite = 0xc0000000;
            public const uint AccessRead = 0x80000000;
            public const uint ShareReadWrite = 3;
            public const uint OpenExisting = 3;
            public const int IOCTL_DISK_GET_MEDIA_TYPES = 0x00070c00;
            public const int FSCTL_LOCK_VOLUME = 0x00090018;
            public const int FSCTL_DISMOUNT_VOLUME = 0x00090020;
            public const int IOCTL_STORAGE_EJECT_MEDIA = 0x002D4808;
            public const int IOCTL_STORAGE_MEDIA_REMOVAL = 0x002D4804;
            public const int IOCTL_STORAGE_CHECK_VERIFY2 = 0x2D0800;
            public const int IOCTL_STORAGE_LOAD_MEDIA = 0x002D480C;
            public const uint ERROR_NOT_CONTAINER = 1207;
            public const uint ERROR_INVALID_PARAMETER = 87;
            public const uint ERROR_NO_NETWORK = 1222;
            public const uint ERROR_EXTENDED_ERROR = 1208;
            public const uint ERROR_INVALID_ADDRESS = 487;
            public const int ERROR_SUCCESS = 0;
            public const int ERROR_MORE_DATA = 234;
            public const int ERROR_ACCESS_DENIED = 5;
            public const int FILE_SHARE_NONE = 0x0;
            public const int FILE_SHARE_READ = 0x1;
            public const int FILE_SHARE_WRITE = 0x2;
            public const int FILE_SHARE_DELETE = 0x4;

            public const int OPEN_EXISTING = 3;
            public const int OPEN_REPARSE_POINT = 0x00200000;
            public const int BACKUP_SEMANTICS = 0x02000000;
            public const uint GENERIC_READ = 0x80000000;
            public const uint GENERIC_WRITE = 0x40000000;
            public const int CREATE_NEW = 1;
            public const int CREATE_ALWAYS = 2;
            public const int FILE_SYSTEM = 0x00000009;
            public const int METHOD_BUFFERED = 0x00000000;
            public const int FSCTL_GET_REPARSE_POINT = (FILE_SYSTEM << 16) | (42 << 2) | METHOD_BUFFERED | (0 << 14);
            public const int SEM_FAILCRITICALERRORS = 0x0001;
            public const int SEM_NOGPFAULTERRORBOX = 0x0002;
            public const int SEM_NOALIGNMENTFAULTEXCEPT = 0x0004;
            public const int SEM_NOOPENFILEERRORBOX = 0x8000;
            public const int SE_ERR_NOASSOC = 31;
            public const uint LVM_GETHEADER = 0x1000 + 31;
            public const uint HDM_GETITEM = 0x1200 + 3;
            public const uint HDM_SETITEM = 0x1200 + 4;
            public const uint SHGFI_ICON = 0x000000100;
            public const uint SHGFI_DISPLAYNAME = 0x000000200;
            public const uint SHGFI_TYPENAME = 0x000000400;
            public const uint SHGFI_ATTRIBUTES = 0x000000800;
            public const uint SHGFI_ICONLOCATION = 0x000001000;
            public const uint SHGFI_EXETYPE = 0x000002000;
            public const uint SHGFI_SYSICONINDEX = 0x000004000;
            public const uint SHGFI_LINKOVERLAY = 0x000008000;
            public const uint SHGFI_SELECTED = 0x000010000;
            public const uint SHGFI_ATTR_SPECIFIED = 0x000020000;
            public const uint SHGFI_LARGEICON = 0x000000000;
            public const uint SHGFI_SMALLICON = 0x000000001;
            public const uint SHGFI_OPENICON = 0x000000002;
            public const uint SHGFI_SHELLICONSIZE = 0x000000004;
            public const uint SHGFI_PIDL = 0x000000008;
            public const uint SHGFI_USEFILEATTRIBUTES = 0x000000010;
            public const uint SHGFI_ADDOVERLAYS = 0x000000020;
            public const uint SHGFI_OVERLAYINDEX = 0x000000040;
            public const uint FO_MOVE = 0x0001;
            public const uint FO_COPY = 0x0002;
            public const uint FO_DELETE = 0x0003;
            public const uint FO_RENAME = 0x0004;
            public const uint FOF_ALLOWUNDO = 0x0040;
            public const uint FOF_NOCONFIRMATION = 0x0010;
            public const uint FOF_SILENT = 0x0004;
            public const uint FOF_NOERRORUI = 0x0400;

            public const int SW_HIDE = 0;
            public const int SW_SHOWNORMAL = 1;
            public const int SW_NORMAL = 1;
            public const int SW_SHOWMINIMIZED = 2;
            public const int SW_SHOWMAXIMIZED = 3;
            public const int SW_MAXIMIZE = 3;
            public const int SW_SHOWNOACTIVATE = 4;
            public const int SW_SHOW = 5;
            public const int SW_MINIMIZE = 6;
            public const int SW_SHOWMINNOACTIVE = 7;
            public const int SW_SHOWNA = 8;
            public const int SW_RESTORE = 9;
            public const int SW_SHOWDEFAULT = 10;
            public const int SW_FORCEMINIMIZE = 11;
            public const int SW_MAX = 11;

            public const int WM_KEYFIRST = 0x0100;
            public const int WM_KEYDOWN = 0x0100;
            public const int WM_KEYUP = 0x0101;
            public const int WM_CHAR = 0x0102;
            public const int WM_DEADCHAR = 0x0103;
            public const int WM_SYSKEYDOWN = 0x0104;
            public const int WM_SYSKEYUP = 0x0105;
            public const int WM_SYSCHAR = 0x0106;
            public const int WM_SYSDEADCHAR = 0x0107;
            public const int WM_UNICHAR = 0x0109;
            public const int WM_KEYLAST = 0x0109;
            public const int WM_ERASEBKGND = 0x14;

            public const int VK_LBUTTON = 0x01;
            public const int VK_RBUTTON = 0x02;
            public const int VK_CANCEL = 0x03;
            public const int VK_MBUTTON = 0x04;
            public const int VK_XBUTTON1 = 0x05;
            public const int VK_XBUTTON2 = 0x06;
            public const int VK_BACK = 0x08;
            public const int VK_TAB = 0x09;
            public const int VK_CLEAR = 0x0C;
            public const int VK_RETURN = 0x0D;
            public const int VK_SHIFT = 0x10;
            public const int VK_CONTROL = 0x11;
            public const int VK_MENU = 0x12;
            public const int VK_PAUSE = 0x13;
            public const int VK_CAPITAL = 0x14;
            public const int VK_KANA = 0x15;
            public const int VK_HANGEUL = 0x15;
            public const int VK_HANGUL = 0x15;
            public const int VK_JUNJA = 0x17;
            public const int VK_FINAL = 0x18;
            public const int VK_HANJA = 0x19;
            public const int VK_KANJI = 0x19;
            public const int VK_ESCAPE = 0x1B;
            public const int VK_CONVERT = 0x1C;
            public const int VK_NONCONVERT = 0x1D;
            public const int VK_ACCEPT = 0x1E;
            public const int VK_MODECHANGE = 0x1F;
            public const int VK_SPACE = 0x20;
            public const int VK_PRIOR = 0x21;
            public const int VK_NEXT = 0x22;
            public const int VK_END = 0x23;
            public const int VK_HOME = 0x24;
            public const int VK_LEFT = 0x25;
            public const int VK_UP = 0x26;
            public const int VK_RIGHT = 0x27;
            public const int VK_DOWN = 0x28;
            public const int VK_SELECT = 0x29;
            public const int VK_PRINT = 0x2A;
            public const int VK_EXECUTE = 0x2B;
            public const int VK_SNAPSHOT = 0x2C;
            public const int VK_INSERT = 0x2D;
            public const int VK_DELETE = 0x2E;
            public const int VK_HELP = 0x2F;
            public const int VK_LWIN = 0x5B;
            public const int VK_RWIN = 0x5C;
            public const int VK_APPS = 0x5D;
            public const int VK_SLEEP = 0x5F;
            public const int VK_NUMPAD0 = 0x60;
            public const int VK_NUMPAD1 = 0x61;
            public const int VK_NUMPAD2 = 0x62;
            public const int VK_NUMPAD3 = 0x63;
            public const int VK_NUMPAD4 = 0x64;
            public const int VK_NUMPAD5 = 0x65;
            public const int VK_NUMPAD6 = 0x66;
            public const int VK_NUMPAD7 = 0x67;
            public const int VK_NUMPAD8 = 0x68;
            public const int VK_NUMPAD9 = 0x69;
            public const int VK_MULTIPLY = 0x6A;
            public const int VK_ADD = 0x6B;
            public const int VK_SEPARATOR = 0x6C;
            public const int VK_SUBTRACT = 0x6D;
            public const int VK_DECIMAL = 0x6E;
            public const int VK_DIVIDE = 0x6F;
            public const int VK_F1 = 0x70;
            public const int VK_F2 = 0x71;
            public const int VK_F3 = 0x72;
            public const int VK_F4 = 0x73;
            public const int VK_F5 = 0x74;
            public const int VK_F6 = 0x75;
            public const int VK_F7 = 0x76;
            public const int VK_F8 = 0x77;
            public const int VK_F9 = 0x78;
            public const int VK_F10 = 0x79;
            public const int VK_F11 = 0x7A;
            public const int VK_F12 = 0x7B;
            public const int VK_F13 = 0x7C;
            public const int VK_F14 = 0x7D;
            public const int VK_F15 = 0x7E;
            public const int VK_F16 = 0x7F;
            public const int VK_F17 = 0x80;
            public const int VK_F18 = 0x81;
            public const int VK_F19 = 0x82;
            public const int VK_F20 = 0x83;
            public const int VK_F21 = 0x84;
            public const int VK_F22 = 0x85;
            public const int VK_F23 = 0x86;
            public const int VK_F24 = 0x87;
            public const int VK_NUMLOCK = 0x90;
            public const int VK_SCROLL = 0x91;
            public const int VK_OEM_NEC_EQUAL = 0x92;
            public const int VK_OEM_FJ_JISHO = 0x92;
            public const int VK_OEM_FJ_MASSHOU = 0x93;
            public const int VK_OEM_FJ_TOUROKU = 0x94;
            public const int VK_OEM_FJ_LOYA = 0x95;
            public const int VK_OEM_FJ_ROYA = 0x96;
            public const int VK_LSHIFT = 0xA0;
            public const int VK_RSHIFT = 0xA1;
            public const int VK_LCONTROL = 0xA2;
            public const int VK_RCONTROL = 0xA3;
            public const int VK_LMENU = 0xA4;
            public const int VK_RMENU = 0xA5;
            public const int VK_BROWSER_BACK = 0xA6;
            public const int VK_BROWSER_FORWARD = 0xA7;
            public const int VK_BROWSER_REFRESH = 0xA8;
            public const int VK_BROWSER_STOP = 0xA9;
            public const int VK_BROWSER_SEARCH = 0xAA;
            public const int VK_BROWSER_FAVORITES = 0xAB;
            public const int VK_BROWSER_HOME = 0xAC;
            public const int VK_VOLUME_MUTE = 0xAD;
            public const int VK_VOLUME_DOWN = 0xAE;
            public const int VK_VOLUME_UP = 0xAF;
            public const int VK_MEDIA_NEXT_TRACK = 0xB0;
            public const int VK_MEDIA_PREV_TRACK = 0xB1;
            public const int VK_MEDIA_STOP = 0xB2;
            public const int VK_MEDIA_PLAY_PAUSE = 0xB3;
            public const int VK_LAUNCH_MAIL = 0xB4;
            public const int VK_LAUNCH_MEDIA_SELECT = 0xB5;
            public const int VK_LAUNCH_APP1 = 0xB6;
            public const int VK_LAUNCH_APP2 = 0xB7;
            public const int VK_OEM_1 = 0xBA;
            public const int VK_OEM_PLUS = 0xBB;
            public const int VK_OEM_COMMA = 0xBC;
            public const int VK_OEM_MINUS = 0xBD;
            public const int VK_OEM_PERIOD = 0xBE;
            public const int VK_OEM_2 = 0xBF;
            public const int VK_OEM_3 = 0xC0;
            public const int VK_OEM_4 = 0xDB;
            public const int VK_OEM_5 = 0xDC;
            public const int VK_OEM_6 = 0xDD;
            public const int VK_OEM_7 = 0xDE;
            public const int VK_OEM_8 = 0xDF;
            public const int VK_OEM_AX = 0xE1;
            public const int VK_OEM_102 = 0xE2;
            public const int VK_ICO_HELP = 0xE3;
            public const int VK_ICO_00 = 0xE4;
            public const int VK_PROCESSKEY = 0xE5;
            public const int VK_ICO_CLEAR = 0xE6;
            public const int VK_PACKET = 0xE7;
            public const int VK_OEM_RESET = 0xE9;
            public const int VK_OEM_JUMP = 0xEA;
            public const int VK_OEM_PA1 = 0xEB;
            public const int VK_OEM_PA2 = 0xEC;
            public const int VK_OEM_PA3 = 0xED;
            public const int VK_OEM_WSCTRL = 0xEE;
            public const int VK_OEM_CUSEL = 0xEF;
            public const int VK_OEM_ATTN = 0xF0;
            public const int VK_OEM_FINISH = 0xF1;
            public const int VK_OEM_COPY = 0xF2;
            public const int VK_OEM_AUTO = 0xF3;
            public const int VK_OEM_ENLW = 0xF4;
            public const int VK_OEM_BACKTAB = 0xF5;
            public const int VK_ATTN = 0xF6;
            public const int VK_CRSEL = 0xF7;
            public const int VK_EXSEL = 0xF8;
            public const int VK_EREOF = 0xF9;
            public const int VK_PLAY = 0xFA;
            public const int VK_ZOOM = 0xFB;
            public const int VK_NONAME = 0xFC;
            public const int VK_PA1 = 0xFD;
            public const int VK_OEM_CLEAR = 0xFE;

            public const int BCM_FIRST = 0x1600;
            public const int BCM_GETIDEALSIZE = (BCM_FIRST + 0x0001);
            public const int BCM_SETNOTE = (BCM_FIRST + 0x0009);
            public const int BS_COMMANDLINK = 0x0000000E;
            public const int BS_DEFCOMMANDLINK = 0x0000000F;
        #endregion
        #region struktury
        [StructLayout(LayoutKind.Sequential)]
        public struct PREVENT_MEDIA_REMOVAL
        {
            public bool PreventMediaRemoval;
        }
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
        public struct SHFILEOPSTRUCT
        {
            public IntPtr hwnd;
            public uint wFunc;
            [MarshalAs(UnmanagedType.LPWStr)]
            public string pFrom;
            [MarshalAs(UnmanagedType.LPWStr)]
            public string pTo;
            public ushort fFlags;
            [MarshalAs(UnmanagedType.Bool)]
            public bool fAnyOperationsAborted;
            public IntPtr hNameMappings;
            [MarshalAs(UnmanagedType.LPWStr)]
            public string lpszProgressTitle;
        }
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
        public struct WIN32_FIND_DATA
        {
            public uint dwFileAttributes;
            public System.Runtime.InteropServices.ComTypes.FILETIME ftCreationTime;
            public System.Runtime.InteropServices.ComTypes.FILETIME ftLastAccessTime;
            public System.Runtime.InteropServices.ComTypes.FILETIME ftLastWriteTime;
            public uint nFileSizeHigh;
            public uint nFileSizeLow;
            public uint dwReserved0;
            public uint dwReserved1;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
            public string cFileName;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 14)]
            public string cAlternateFileName;
        }
        [StructLayout(LayoutKind.Sequential)]
        public struct SIZE
        {
            public int cx;
            public int cy;

            public SIZE(int cx, int cy)
            {
                this.cx = cx;
                this.cy = cy;
            }
        }
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
        public struct SymbolicLinkReparseBuffer
        {
            public ushort SubstituteNameOffset;
            public ushort SubstituteNameLength;
            public ushort PrintNameOffset;
            public ushort PrintNameLength;
            public ulong Flags; // it seems that the docu is missing this entry (at least 2008-03-07)
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1024)]
            public string PathBuffer;
        }
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
        public struct MountPointReparseBuffer
        {
            public ushort SubstituteNameOffset;
            public ushort SubstituteNameLength;
            public ushort PrintNameOffset;
            public ushort PrintNameLength;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1024)]
            public string PathBuffer;
        }
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
        public struct REPARSE_DATA_BUFFER_SYM
        {
            internal uint ReparseTag;
            internal ushort ReparseDataLength;
            internal ushort Reserved;
            public SymbolicLinkReparseBuffer _SymbolicLinkReparseBuffer;
        }
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
        public struct REPARSE_DATA_BUFFER_MOUNT
        {
            internal uint ReparseTag;
            internal ushort ReparseDataLength;
            internal ushort Reserved;
            public MountPointReparseBuffer _MountPointReparseBuffer;
        }
        [System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)]
        public struct MSG
        {
            public Int32 hwnd;
            public Int32 message;
            public Int32 wParam;
            public Int32 lParam;
            public Int32 time;
            public POINT pt;
        }
        [StructLayout(LayoutKind.Sequential)]
        public struct POINT
        {
            public int X;
            public int Y;

            public System.Drawing.Point Point
            {
                get
                {
                    return new System.Drawing.Point(X, Y);
                }
            }
        }
        [StructLayout(LayoutKind.Sequential)]
        public struct RECT
        {
            public int left;
            public int top;
            public int right;
            public int bottom;

            public int Width
            {
                get { return right - left; }
            }

            public int Height
            {
                get { return bottom - top; }
            }
        }
        [System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)]
        public struct HDITEM
        {
            public W32_HDI mask;
            public int cxy;
            public String pszText;
            public IntPtr hbm;
            public int cchTextMax;
            public W32_HDF fmt;
            public int lParam;
            public int iImage;
            public int iOrder;
            public uint type;
            public IntPtr pvFilter;
        }
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
        public struct SHFILEINFO
        {
            public IntPtr hIcon;
            public int iIcon;
            public uint dwAttributes;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
            public string szDisplayName;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)]
            public string szTypeName;
        };
        [System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential, Pack = 8)]
        public struct BROWSEINFO
        {
            public IntPtr hwndOwner;
            public IntPtr pidlRoot;
            public IntPtr pszDisplayName;
            [System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPTStr)]
            public string lpszTitle;
            public int ulFlags;
            [System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.FunctionPtr)]
            public BFFCALLBACK lpfn;
            public IntPtr lParam;
            public int iImage;
        }
        [System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)]
        public struct DEVICE_MEDIA_INFO
        {
            public Int64 Cylinders;
            public StorageMediaType MediaType;
            public UInt32 TracksPerCylinder;
            public UInt32 SectorsPerTrack;
            public UInt32 BytesPerSector;
            public UInt32 NumberMediaSides;
            public MediaCharacteristics MediaCharacteristics;
        }
        [System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)]
        public struct GET_MEDIA_TYPES
        {

            public DeviceType DeviceType;
            public UInt32 MediaInfoCount;
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 50)]
            public DEVICE_MEDIA_INFO[] MediaInfo;
        }
        [StructLayout(LayoutKind.Sequential)]
        public struct DISK_GEOMETRY
        {
           public long Cylinders;
           public StorageMediaType MediaType;
           public int TracksPerCylinder;
           public int SectorsPerTrack;
           public int BytesPerSector;

           public long DiskSize
           {
             get
             {
               return Cylinders * (long)TracksPerCylinder * (long)SectorsPerTrack * (long)BytesPerSector;
             }
           }
        }
        [System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)]
        public class NETRESOURCE
        {
            public ResourceScope dwScope = 0;
            public ResourceType dwType = 0;
            public ResourceDisplayType dwDisplayType = 0;
            public ResourceUsage dwUsage = 0;
            public string lpLocalName = null;
            public string lpRemoteName = null;
            public string lpComment = null;
            public string lpProvider = null;
        };
        [System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential, CharSet = System.Runtime.InteropServices.CharSet.Unicode)]
        public struct SHARE_INFO_2
        {
            [System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]
            public string NetName;
            public ShareType ShareType;
            [System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]
            public string Remark;
            public int Permissions;
            public int MaxUsers;
            public int CurrentUsers;
            [System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]
            public string Path;
            [System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]
            public string Password;
        }
        [System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential, CharSet = System.Runtime.InteropServices.CharSet.Unicode)]
        public struct SHARE_INFO_1
        {
            [System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]
            public string NetName;
            public ShareType ShareType;
            [System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]
            public string Remark;
        }
        #endregion
        #region enumeracie
        public enum W32_HDF : int
        {
            HDF_LEFT = 0x0000,
            HDF_RIGHT = 0x0001,
            HDF_CENTER = 0x0002,
            HDF_JUSTIFYMASK = 0x0003,
            HDF_NOJUSTIFY = 0xFFFC,
            HDF_RTLREADING = 0x0004,
            HDF_SORTDOWN = 0x0200,
            HDF_SORTUP = 0x0400,
            HDF_SORTED = 0x0600,
            HDF_NOSORT = 0xF1FF,
            HDF_IMAGE = 0x0800,
            HDF_BITMAP_ON_RIGHT = 0x1000,
            HDF_BITMAP = 0x2000,
            HDF_STRING = 0x4000,
            HDF_OWNERDRAW = 0x8000
        }
        public enum W32_HDI : int
        {
            HDI_WIDTH = 0x0001,
            HDI_HEIGHT = HDI_WIDTH,
            HDI_TEXT = 0x0002,
            HDI_FORMAT = 0x0004,
            HDI_LPARAM = 0x0008,
            HDI_BITMAP = 0x0010,
            HDI_IMAGE = 0x0020,
            HDI_DI_SETITEM = 0x0040,
            HDI_ORDER = 0x0080,
            HDI_FILTER = 0x0100
        }
        public enum DeviceType : uint
        {
            FILE_DEVICE_8042_PORT = 0x00000027,
            FILE_DEVICE_ACPI = 0x00000032,
            FILE_DEVICE_BATTERY = 0x00000029,
            FILE_DEVICE_BEEP = 0x00000001,
            FILE_DEVICE_BUS_EXTENDER = 0x0000002a,
            FILE_DEVICE_CD_ROM = 0x00000002,
            FILE_DEVICE_CD_ROM_FILE_SYSTEM = 0x00000003,
            FILE_DEVICE_CHANGER = 0x00000030,
            FILE_DEVICE_CONTROLLER = 0x00000004,
            FILE_DEVICE_DATALINK = 0x00000005,
            FILE_DEVICE_DFS = 0x00000006,
            FILE_DEVICE_DFS_FILE_SYSTEM = 0x00000035,
            FILE_DEVICE_DFS_VOLUME = 0x00000036,
            FILE_DEVICE_DISK = 0x00000007,
            FILE_DEVICE_DISK_FILE_SYSTEM = 0x00000008,
            FILE_DEVICE_DVD = 0x00000033,
            FILE_DEVICE_FILE_SYSTEM = 0x00000009,
            FILE_DEVICE_FIPS = 0x0000003a,
            FILE_DEVICE_FULLSCREEN_VIDEO = 0x00000034,
            FILE_DEVICE_INPORT_PORT = 0x0000000a,
            FILE_DEVICE_KEYBOARD = 0x0000000b,
            FILE_DEVICE_KS = 0x0000002f,
            FILE_DEVICE_KSEC = 0x00000039,
            FILE_DEVICE_MAILSLOT = 0x0000000c,
            FILE_DEVICE_MASS_STORAGE = 0x0000002d,
            FILE_DEVICE_MIDI_IN = 0x0000000d,
            FILE_DEVICE_MIDI_OUT = 0x0000000e,
            FILE_DEVICE_MODEM = 0x0000002b,
            FILE_DEVICE_MOUSE = 0x0000000f,
            FILE_DEVICE_MULTI_UNC_PROVIDER = 0x00000010,
            FILE_DEVICE_NAMED_PIPE = 0x00000011,
            FILE_DEVICE_NETWORK = 0x00000012,
            FILE_DEVICE_NETWORK_BROWSER = 0x00000013,
            FILE_DEVICE_NETWORK_FILE_SYSTEM = 0x00000014,
            FILE_DEVICE_NETWORK_REDIRECTOR = 0x00000028,
            FILE_DEVICE_NULL = 0x00000015,
            FILE_DEVICE_PARALLEL_PORT = 0x00000016,
            FILE_DEVICE_PHYSICAL_NETCARD = 0x00000017,
            FILE_DEVICE_PRINTER = 0x00000018,
            FILE_DEVICE_SCANNER = 0x00000019,
            FILE_DEVICE_SCREEN = 0x0000001c,
            FILE_DEVICE_SERENUM = 0x00000037,
            FILE_DEVICE_SERIAL_MOUSE_PORT = 0x0000001a,
            FILE_DEVICE_SERIAL_PORT = 0x0000001b,
            FILE_DEVICE_SMARTCARD = 0x00000031,
            FILE_DEVICE_SMB = 0x0000002e,
            FILE_DEVICE_SOUND = 0x0000001d,
            FILE_DEVICE_STREAMS = 0x0000001e,
            FILE_DEVICE_TAPE = 0x0000001f,
            FILE_DEVICE_TAPE_FILE_SYSTEM = 0x00000020,
            FILE_DEVICE_TERMSRV = 0x00000038,
            FILE_DEVICE_TRANSPORT = 0x00000021,
            FILE_DEVICE_UNKNOWN  = 0x00000022,
            FILE_DEVICE_VDM = 0x0000002c,
            FILE_DEVICE_VIDEO = 0x00000023,
            FILE_DEVICE_VIRTUAL_DISK = 0x00000024,
            FILE_DEVICE_WAVE_IN = 0x00000025,
            FILE_DEVICE_WAVE_OUT = 0x00000026
        }
        [Flags]
        public enum MediaCharacteristics : uint
        {
            None = 0,
            Erasable = 0x00000001,
            WriteOnce = 0x00000002,
            ReadOnly = 0x00000004,
            ReadWrite = 0x00000008,
            WriteProtected = 0x00000100,
            Mounted = 0x80000000
        }
        public enum StorageMediaType : uint
        {
            Unknown = 0,
            F5_1Pt2_512 = 1,
            F3_1Pt44_512 = 2,
            F3_2Pt88_512 = 3,
            F3_20Pt8_512 = 4,
            F3_720_512 = 5,
            F5_360_512 = 6,
            F5_320_512 = 7,
            F5_320_1024 = 8,
            F5_180_512 = 9,
            F5_160_512 = 10,
            RemovableMedia = 11,
            FixedMedia = 12,
            F3_120M_512 = 13,
            F3_640_512 = 14,
            F5_640_512 = 15,
            F5_720_512 = 16,
            F3_1Pt2_512 = 17,
            F3_1Pt23_1024 = 18,
            F5_1Pt23_1024 = 19,
            F3_128Mb_512 = 20,
            F3_230Mb_512 = 21,
            F8_256_128 = 22,
            F3_200Mb_512 = 23,
            F3_240M_512 = 24,
            F3_32M_512 = 25,
            DDS_4mm = 0x20,
            MiniQic = 0x21,
            Travan = 0x22,
            QIC = 0x23,
            MP_8mm = 0x24,
            AME_8mm = 0x25,
            AIT1_8mm = 0x26,
            DLT = 0x27,
            NCTP = 0x28,
            IBM_3480 = 0x29,
            IBM_3490E = 0x2A,
            IBM_Magstar_3590 = 0x2B,
            IBM_Magstar_MP = 0x2C,
            STK_DATA_D3 = 0x2D,
            SONY_DTF = 0x2E,
            DV_6mm = 0x2F,
            DMI = 0x30,
            SONY_D2 = 0x31,
            CLEANER_CARTRIDGE = 0x32,
            CD_ROM = 0x33,
            CD_R = 0x34,
            CD_RW = 0x35,
            DVD_ROM = 0x36,
            DVD_R = 0x37,
            DVD_RW = 0x38,
            MO_3_RW = 0x39,
            MO_5_WO = 0x3A,
            MO_5_RW = 0x3B,
            MO_5_LIMDOW = 0x3C,
            PC_5_WO = 0x3D,
            PC_5_RW = 0x3E,
            PD_5_RW = 0x3F,
            ABL_5_WO = 0x40,
            PINNACLE_APEX_5_RW = 0x41,
            SONY_12_WO = 0x42,
            PHILIPS_12_WO = 0x43,
            HITACHI_12_WO = 0x44,
            CYGNET_12_WO = 0x45,
            KODAK_14_WO = 0x46,
            MO_NFR_525 = 0x47,
            NIKON_12_RW = 0x48,
            IOMEGA_ZIP = 0x49,
            IOMEGA_JAZ = 0x4A,
            SYQUEST_EZ135 = 0x4B,
            SYQUEST_EZFLYER = 0x4C,
            SYQUEST_SYJET = 0x4D,
            AVATAR_F2 = 0x4E,
            MP2_8mm = 0x4F,
            DST_S = 0x50,
            DST_M = 0x51,
            DST_L = 0x52,
            VXATape_1 = 0x53,
            VXATape_2 = 0x54,
            STK_9840 = 0x55,
            LTO_Ultrium = 0x56,
            LTO_Accelis = 0x57,
            DVD_RAM = 0x58,
            AIT_8mm = 0x59,
            ADR_1 = 0x5A,
            ADR_2 = 0x5B,
            STK_9940 = 0x5C,
            SAIT = 0x5D,
            VXATape = 0x5E
        }
        public enum ResourceScope
        {
            RESOURCE_CONNECTED = 1,
            RESOURCE_GLOBALNET,
            RESOURCE_REMEMBERED,
            RESOURCE_RECENT,
            RESOURCE_CONTEXT
        };
        public enum ResourceType
        {
            RESOURCETYPE_ANY,
            RESOURCETYPE_DISK,
            RESOURCETYPE_PRINT,
            RESOURCETYPE_RESERVED
        };
        public enum ResourceUsage : uint
        {
            RESOURCEUSAGE_CONNECTABLE = 0x00000001,
            RESOURCEUSAGE_CONTAINER = 0x00000002,
            RESOURCEUSAGE_NOLOCALDEVICE = 0x00000004,
            RESOURCEUSAGE_SIBLING = 0x00000008,
            RESOURCEUSAGE_ATTACHED = 0x00000010,
            RESOURCEUSAGE_ALL = (RESOURCEUSAGE_CONNECTABLE | RESOURCEUSAGE_CONTAINER | RESOURCEUSAGE_ATTACHED),
            RESOURCEUSAGE_CONTAINER_1 = 0x80000002,
        };
        public enum ResourceDisplayType
        {
            RESOURCEDISPLAYTYPE_GENERIC,
            RESOURCEDISPLAYTYPE_DOMAIN,
            RESOURCEDISPLAYTYPE_SERVER,
            RESOURCEDISPLAYTYPE_SHARE,
            RESOURCEDISPLAYTYPE_FILE,
            RESOURCEDISPLAYTYPE_GROUP,
            RESOURCEDISPLAYTYPE_NETWORK,
            RESOURCEDISPLAYTYPE_ROOT,
            RESOURCEDISPLAYTYPE_SHAREADMIN,
            RESOURCEDISPLAYTYPE_DIRECTORY,
            RESOURCEDISPLAYTYPE_TREE,
            RESOURCEDISPLAYTYPE_NDSCONTAINER
        };
        public enum ErrorCodes
        {
            NO_ERROR = 0,
            ERROR_NO_MORE_ITEMS = 259
        };
        public enum ShareType : uint
        {
            Disk = 0,
            Printer = 1,
            Device = 2,
            IPC = 3,
            Special = 0x80000000,
        }
        #endregion

        /// <summary>Trieda Kernel32</summary>
        public class Kernel32
        {
            [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError=true)]
            public static extern IntPtr FindFirstFile(string lpFileName, out IWin32.WIN32_FIND_DATA lpFindFileData);
            [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
            public static extern bool FindNextFile(IntPtr hFindFile, out IWin32.WIN32_FIND_DATA lpFindFileData);
            [DllImport("kernel32.dll")]
            public static extern bool FindClose(IntPtr hFindFile);
            [DllImport("kernel32.dll", SetLastError=true)]
            public static extern int CreateDirectory(string lpPathName, IntPtr lpSecurityAttributes);
            [DllImport("kernel32.dll", SetLastError = true)]
            public static extern int MoveFile(string lpExistingFileName, string lpNewFileName);
            [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
            public static extern int RemoveDirectory(string lpPathName);
            [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
            public static extern int DeleteFile(string lpFileName);
            [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
            public static extern uint GetFileAttributes(string lpFileName);
            [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Ansi)]
            public static extern IntPtr CreateFile(string lpFileName, uint dwDesiredAccess, uint dwShareMode, IntPtr lpSecurityAttributes, uint dwCreationDisposition, uint dwFlagsAndAttributes, IntPtr hTemplateFile);
            [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
            public static extern bool DeviceIoControl(IntPtr hDevice, int dwIoControlCode, IntPtr InBuffer, int nInBufferSize, IntPtr OutBuffer, int nOutBufferSize, ref int pBytesReturned, IntPtr lpOverlapped);
            [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
            public static extern bool DeviceIoControl(IntPtr hDevice, int dwIoControlCode, ref bool InBuffer, int nInBufferSize, IntPtr OutBuffer, int nOutBufferSize, ref int pBytesReturned, IntPtr lpOverlapped);
            [DllImport("kernel32.dll", SetLastError = true)]
            public static extern bool CloseHandle(IntPtr hHandle);
            [DllImport("kernel32.dll")]
            public static extern uint SetErrorMode(uint hHandle);
            [DllImport("kernel32.dll")]
            public static extern int CompareFileTime(ref System.Runtime.InteropServices.ComTypes.FILETIME lpFileTime1, ref System.Runtime.InteropServices.ComTypes.FILETIME lpFileTime2);
            [DllImport("kernel32.dll", SetLastError = true)]
            public static extern bool DeviceIoControl(IntPtr hDevice, uint dwIoControlCode, IntPtr lpInBuffer, int nInBufferSize, IntPtr lpOutBuffer, int nOutBufferSize, ref UInt32 lpBytesReturned, IntPtr lpOverlapped);
            [DllImport("Kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
            public static extern bool GetVolumeInformation(string RootPathName, System.Text.StringBuilder VolumeNameBuffer, int VolumeNameSize, out uint VolumeSerialNumber, out uint MaximumComponentLength, out uint FileSystemFlags, System.Text.StringBuilder FileSystemNameBuffer, int nFileSystemNameSize);
            [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
            public static extern bool SetVolumeLabel(string lpRootPathName, string lpVolumeName);
            [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
            public static extern bool GetDiskFreeSpace(string lpRootPathName, out uint lpSectorsPerCluster, out uint lpBytesPerSector, out uint lpNumberOfFreeClusters, out uint lpTotalNumberOfClusters);
            [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
            public static extern bool SetFileAttributes(string lpFileName, uint dwFileAttributes);
        }
        /// <summary>Trieda User32</summary>
        public class User32
        {
            [DllImport("user32.dll")]
            public static extern void PostQuitMessage(int nExitCode);
            [DllImport("user32.dll")]
            public static extern short GetAsyncKeyState(int vKey);
            [DllImport("user32.dll", CharSet = CharSet.Auto)]
            public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, out IWin32.SIZE lParam);
            [DllImport("user32.dll", CharSet = CharSet.Auto)]
            public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, string lParam);
            [System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true)]
            public static extern bool PeekMessage(ref IWin32.MSG lpMsg, Int32 hwnd, Int32 wMsgFilterMin, Int32 wMsgFilterMax, Int32 wRemoveMsg);
            [System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true)]
            public static extern Int32 DispatchMessage(ref IWin32.MSG lpMsg);
            [System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true)]
            public static extern Int32 TranslateMessage(ref IWin32.MSG lpMsg);
            [System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true)]
            public static extern bool GetMessage(ref IWin32.MSG lpMsg, Int32 hwnd, Int32 wMsgFilterMin, Int32 wMsgFilterMax);
            [DllImport("User32.dll", CharSet = CharSet.Auto)]
            public static extern IntPtr SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
            [DllImport("user32.dll")]
            public static extern bool GetWindowRect(IntPtr hWnd, ref IWin32.RECT rect);
            [System.Runtime.InteropServices.DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto, SetLastError = false)]
            public static extern IntPtr SendMessage(IntPtr hWnd, Int32 Msg, int wParam, ref IWin32.HDITEM lParam);
            [DllImport("user32.dll")]
            public static extern bool DestroyIcon(IntPtr hIcon);
            [System.Runtime.InteropServices.DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
            public static extern IntPtr SendMessage(IntPtr hWnd, int Msg, int wParam, [System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPStr)] System.Text.StringBuilder lParam);
            [System.Runtime.InteropServices.DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
            public static extern bool SetForegroundWindow(IntPtr pHandle);
            [DllImport("user32.dll", SetLastError = true)]
            public static extern IntPtr PostMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);
            [System.Runtime.InteropServices.DllImport("user32.dll")]
            public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, UIntPtr wParam, IntPtr lParam);
        }
        /// <summary>Trieda Shell32</summary>
        public class Shell32
        {
            [DllImport("shell32.dll")]
            public static extern IntPtr ShellExecute(IntPtr hwnd, string lpOperation, string lpFile, string lpParameters, string lpDirectory, int nShowCmd);
            [DllImport("shell32.dll", CharSet = CharSet.Auto)]
            public static extern IntPtr SHGetFileInfo(string pszPath, uint dwFileAttributes, ref IWin32.SHFILEINFO psfi, uint cbFileInfo, uint uFlags);
            [System.Runtime.InteropServices.DllImport("shell32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
            public static extern IntPtr SHBrowseForFolder(ref IWin32.BROWSEINFO bi);
            [System.Runtime.InteropServices.DllImport("shell32.dll", CharSet = System.Runtime.InteropServices.CharSet.Unicode)]
            public static extern uint SHGetPathFromIDList(IntPtr pidl, [System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)] System.Text.StringBuilder pszPath);
            [DllImport("shell32.dll", CharSet = CharSet.Unicode, EntryPoint = "SHFileOperation")]
            public static extern int SHFileOperation(ref SHFILEOPSTRUCT lpFileOp);
        }

        /// <summary>Trieda Mpr</summary>
        public class Mpr
        {
            [System.Runtime.InteropServices.DllImport("Mpr.dll", EntryPoint = "WNetOpenEnumA", CallingConvention = System.Runtime.InteropServices.CallingConvention.Winapi)]
            public static extern ErrorCodes WNetOpenEnum(ResourceScope dwScope, ResourceType dwType, ResourceUsage dwUsage, NETRESOURCE p, out IntPtr lphEnum);
            [System.Runtime.InteropServices.DllImport("Mpr.dll", EntryPoint = "WNetCloseEnum", CallingConvention = System.Runtime.InteropServices.CallingConvention.Winapi)]
            public static extern ErrorCodes WNetCloseEnum(IntPtr hEnum);
            [System.Runtime.InteropServices.DllImport("Mpr.dll", EntryPoint = "WNetEnumResourceA", CallingConvention = System.Runtime.InteropServices.CallingConvention.Winapi)]
            public static extern ErrorCodes WNetEnumResource(IntPtr hEnum, ref uint lpcCount, IntPtr buffer, ref uint lpBufferSize);
            [System.Runtime.InteropServices.DllImport("mpr", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
            public static extern uint WNetConnectionDialog(IntPtr hwnd, uint dwType);
            [System.Runtime.InteropServices.DllImport("mpr", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
            public static extern uint WNetDisconnectDialog(IntPtr hwnd, uint dwType);
        }

        /// <summary>Trieda Netapi32</summary>
        public class Netapi32
        {
            [System.Runtime.InteropServices.DllImport("netapi32", CharSet = System.Runtime.InteropServices.CharSet.Unicode)]
            public static extern int NetShareEnum(string lpServerName, int dwLevel, out IntPtr lpBuffer, int dwPrefMaxLen, out int entriesRead, out int totalEntries, ref IntPtr hResume);
            [System.Runtime.InteropServices.DllImport("Netapi32", SetLastError = true), System.Security.SuppressUnmanagedCodeSecurityAttribute]
            public static extern int NetApiBufferFree(IntPtr pBuf);
        }

        public class GDI32
        {
            [DllImport("Gdi32.dll", EntryPoint = "CreateRoundRectRgn")]
            public static extern IntPtr CreateRoundRectRgn(int nLeftRect, int nTopRect, int nRightRect, int nBottomRect, int nWidthEllipse, int nHeightEllipse);
        }
    }
}
